#include <QPainter>

#include "RenderArea.h"

RenderArea::RenderArea(QWidget *parent)
: QWidget(parent)
, _v(0.0)
, _s(1.0)
, _gray(false)
{
}

void RenderArea::setScale(float s)
{
	_s = s;
	repaint();
}

void RenderArea::setValue(float v, bool gray)
{
	_v = v;
	_gray = gray;
	repaint();
}

void RenderArea::paintEvent(QPaintEvent *)
{
	QPainter painter(this);
	painter.setBrush(QBrush(QColor(Qt::white), Qt::SolidPattern));
	painter.drawRect(QRect(0, 0, width() - 1, height() - 1));

	if(_gray)
		painter.setBrush(QBrush(QColor(Qt::gray), Qt::SolidPattern));
	else
		painter.setBrush(QBrush(QColor(Qt::blue), Qt::SolidPattern));
	painter.drawRect(QRect(width() / 2, 0, width() / 2 * (_v * _s), height() - 1));
}
